<?php

/**
 * 
 * @author vu
 *
 */
class Dao_CodeControlDAO extends Dao_AbstractDAO {
	
	public function __construct($db = null) {
		parent::__construct($db);
		$this->tableName = "M_CODE_CONTROL";
		$this->key = "ID";
		$this->classModel = "Model_CodeControl";
	}
	
	/**
	 * get code control by code
	 * @param string $code
	 * @return Model_CodeControl
	 */
	public function getCodeControlByCode($code) {
		$query = " SELECT ";
		$query .= " ID, ";
		$query .= " `CODE`, ";
		$query .= " `VALUE`, ";
		$query .= " DESCRIPTION ";
		$query .= " FROM ";
		$query .= " M_CODE_CONTROL ";
		$query .= " WHERE ";
		$query .= " CODE = '" . $code . "'";
	
		$db = $this->db;
		$res = $db->query($query);
	
		$arrayControl = $this->getObjects($res);
		if (count($arrayControl) > 0) {
			return $arrayControl[0];
		} else {
			return null;
		}
	}
	
	/**
	 * get value by code
	 * @param string $code
	 * @return string
	 */
	public function getValueByCode($code) {
		$codeControl = $this->getCodeControlByCode($code);
		$value = null;
		if ($codeControl !== null) {
			$value = $codeControl->getValue();
		}
		
		return $value;
	}
	
	
	
}